#ifndef KEYWORDLIB_H
#define KEYWORDLIB_H

#include <QObject>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QMap>
#include <QVector>
#include "mytypes.h"
class KeyWordLib : public QObject
{
    Q_OBJECT

private:
    explicit KeyWordLib(QObject *parent = nullptr);
    static KeyWordLib* _instance;

    void InitDate();        //初始化数据

    Yzty::WordLibCode getindex(int index);

    void CacheLack(Yzty::WordLibCode code);

public:
    static KeyWordLib* GetInstance(QObject* parent=nullptr);
    virtual ~KeyWordLib();

    bool DeleteWordLib(Yzty::WordLibCode code);                                                     //删除关键词库
    bool AddKeyWordLib(const QString& TypeName,const QStringList& words);                           //添加关键词库
    bool ModiftyWord(Yzty::WordLibCode code,int wordindex,const QString& word);                     //修改关键词
    bool DeleteWord(Yzty::WordLibCode code,int wordindex);                                          //删除关键词

    const QVector<QString>& GetWordList(Yzty::WordLibCode code);
    QString GetWord(Yzty::WordLibCode code,int wordindex);
    QString GetLibName(Yzty::WordLibCode code);
    const QMap<Yzty::WordLibCode,QString>& GetLibNameList();

    int GetKeyWordNums(Yzty::WordLibCode code);

signals:

public slots:


private:
//    QSqlDatabase sqlite;
//    QSqlQuery query;

    int                                         maxindex;       //当前最大关键词库索引
    QVector<int>                                hashtable;
    QMap<Yzty::WordLibCode,QString>             typenames;      //关键词库code与名称的映射
    QMap<Yzty::WordLibCode,QVector<QString>>    word_cache;    //关键词库code与词组的映射
};

#endif // KEYWORDLIB_H
